#include <stdio.h>
#include <stdlib.h>

typedef int HashVal; /* 默认散列值为int型*/
#define kMaxLen 10

/* 算法11-10：英文字典的散列 StringHash(string, table_size) */
HashVal StringHash(char string[], int table_size) {
    HashVal hash_v;
    int i;

    hash_v = 0;
    i = 0;
    while (string[i] != '\0') {
        hash_v = (hash_v << 5) + (string[i] - 'a');
        i++;
    }
    return hash_v % table_size;
}
/* 算法11-10 结束 */

int main(void) {
    char string[kMaxLen + 1];
    int table_size;

    scanf("%s %d", string, &table_size);
    printf("%d", StringHash(string, table_size));

    return 0;
}